package com.forlove.app.qselect.friend.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.widget.TextView;

import com.forlove.app.R;
import com.forlove.app.common.base.mvp.presenter.IBasePresenter;
import com.forlove.app.common.utils.ViewUtils;
import com.forlove.app.common.widget.recyview.BaseRecyclerAdapter;
import com.forlove.app.common.widget.recyview.ViewHolder;
import com.forlove.app.qselect.friend.entity.FriendEntity;

import java.util.List;

/**
 * 搜索好友结果
 * Created by yjl on 2017/10/14.
 */

public class SearchFriendResultAdapter extends BaseRecyclerAdapter<FriendEntity> {

    private IBasePresenter iBasePresenter;
    private String strQuery;

    public SearchFriendResultAdapter(Context context, int itemView, List<FriendEntity> mDatas, IBasePresenter presenter) {
        super(context, itemView, mDatas);
        this.iBasePresenter = presenter;
    }

    public void setQueryString(String query) {
        this.strQuery = query;
    }

    @Override
    protected void convertView(ViewHolder holder, FriendEntity entity, int position) {
        iBasePresenter.loadImageView(mContext, holder.getView(R.id.view_friend_photo),
                entity.img, R.mipmap.image_mine_friend_avatar);
        holder.setText(R.id.text_friend_nickname, entity.realname);
        holder.setText(R.id.text_friend_mobile, entity.mobile);
        holder.setText(R.id.text_view_state, mContext.getString(R.string.str_added_friend));
        holder.setBackgroundColor(R.id.text_view_state, Color.parseColor("#ffffff"));
        holder.setTextColorRes(R.id.text_view_state, R.color.color_text_title);
        if (!TextUtils.isEmpty(strQuery) && entity.mobile.contains(strQuery)) {
            int start = entity.mobile.indexOf(strQuery);
            ViewUtils.customTextColor((TextView) holder.getView(R.id.text_friend_mobile), Color.parseColor("#2ac2b9"), start, start + strQuery.length());
        }
        if (!TextUtils.isEmpty(strQuery) && entity.realname.contains(strQuery)) {
            int start = entity.realname.indexOf(strQuery);
            ViewUtils.customTextColor((TextView) holder.getView(R.id.text_friend_nickname), Color.parseColor("#2ac2b9"), start, start + strQuery.length());
        }
    }

}
